#include "block_file.h"
#include "order_manager.h"
#include <cstdio>
int main(int argc, char** argv)
{
    typedef file_block<1024> order_file_data;
    Order::OrderInfo         info;
    if (argc == 1) {
        order_manager::fill_order(info);
        printf("origin order size is %lu\n", sizeof(info));
        printf("origin order  is %s\n", info.string().data());
        FBE::Order::OrderInfoModel model;
        model.serialize(info);
        auto&           buffer = model.buffer();
        order_file_data block;
        block.data_code = static_cast<uint32_t>(1000);
        block.data_len  = static_cast<uint32_t>(buffer.size());
        memcpy((void*)block.data_buf, (void*)buffer.data(), buffer.size());
        block_file<order_file_data> file_b("./order.dat");
        int                         ret = file_b.append_file(block);
        if (ret != 0) {
            printf("data write failed  ret = %d\n", ret);
        }
        else {
            printf("data write success  ret = %d\n", ret);
        }
    }
    else {
        //做读取测试
        block_file<order_file_data>                   file_b("./order.dat");
        std::vector<std::shared_ptr<order_file_data>> result;
        int                                           ret = file_b.load_file(result);
        if (ret != 0) {
            printf("data load failed  ret = %d\n", ret);
            return -1;
        }
        else {
            printf("data load success  ret = %d\n", ret);
        }
        for (std::size_t i = 0; i < result.size(); ++i) {
            auto                            ptr = result[i];
            std::shared_ptr<FBE::FBEBuffer> buffer =
                std::make_shared<FBE::FBEBuffer>((void*)(ptr->data_buf), ptr->data_len);

            FBE::Order::OrderInfoModel model(buffer);
            Order::OrderInfo           value;
            model.deserialize(value);
            printf("data is %s\n", value.string().data());
        }
    }
    return 0;
}